package cn.stylefeng.guns.modular.system.service.Myservice;

import cn.stylefeng.guns.modular.system.entity.CheckSales;
import cn.stylefeng.guns.modular.system.entity.SalsOrderCheck;
import cn.stylefeng.guns.modular.system.mapper.SalsOrderCheckMapper;
import cn.stylefeng.guns.modular.system.model.params.paramsDTO.CheckDTO;
import cn.stylefeng.guns.modular.system.service.CheckSalesService;
import cn.stylefeng.guns.modular.system.service.SalsOrderCheckService;
import cn.stylefeng.guns.sys.core.StatusCode.SalesOrderCode;
import cn.stylefeng.guns.sys.core.shiro.ShiroKit;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

/**
 * @Author : xiaofei
 * @Date: 2019/7/4
 */
@Service
public class SalsCheckService extends ServiceImpl<SalsOrderCheckMapper, SalsOrderCheck> {


    @Autowired
    private SalsOrderCheckService salsOrderCheckService;
    @Autowired
    private CheckSalesService checkSalesService;
    /**
     * 审核
     * @param checkDTO
     */
    public void shenhe(CheckDTO checkDTO){


        //查出当前的订单信息
        SalsOrderCheck salsOrderCheck = salsOrderCheckService.getById(checkDTO.getId());
        if (checkDTO.getCode() == SalesOrderCode.PASS.getVal()){

            //当前是普通提交订单一审
            if (salsOrderCheck.getStatus() == SalesOrderCode.SALSPENDING.getVal()){
                salsOrderCheck.setPass(SalesOrderCode.PASS.getVal());
                salsOrderCheck.setStatus(SalesOrderCode.NODE1.getVal());
                salsOrderCheck.setRemark(checkDTO.getAdvice());
                salsOrderCheckService.getBaseMapper().updateById(salsOrderCheck);

                //插入到审核历史表里面
                CheckSales checkSales = new CheckSales();
                checkSales.setSalesOrderId(salsOrderCheck.getIndetOrderId());
                checkSales.setAdvice(checkDTO.getAdvice());
                checkSales.setAuditor(ShiroKit.getUserNotNull().getId());
                checkSales.setStatus(SalesOrderCode.PASS.getVal());
                checkSales.setTime(new Date());
                checkSalesService.save(checkSales);



            }
        }

    }





}
